﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using LibrarySolution.ComMethod;

namespace LibrarySolution.DB
{
    class ConnFactory
    {        
        public static SqlConnection getConnection()
        {
            return createConnection();
        }
        /// <summary>
        ///  创建连接
        /// </summary>
        /// <returns></returns>
        private static SqlConnection createConnection()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = GlobalVar.connString;
            return conn;
        }
        /// <summary>
        ///  打开连接
        /// </summary>
        /// <param name="conn"></param>
        public static void openConn(SqlConnection conn)
        {
            if ((conn != null) && conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
        }
        /// <summary>
        ///  关闭连接
        /// </summary>
        /// <param name="conn"></param>
        public static void closeConn(SqlConnection conn)
        {
            if ((conn != null) && conn.State != ConnectionState.Closed)
            {
                conn.Close();
            }
        }
    }
}
